// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const db = cloud.database()
  if(event.level==3){
    var result=[];
    return await db.collection('scanCode')
    .where({
      brandidThree:event.brandid,
      openidThree: wxContext.OPENID,
    }).update({
      data: {
        isSubmitThree:true
        },
    })
  }else if(event.level==4){
    return await db.collection('scanCode')
    .where({
      brandidFour:event.brandid,
      openidFour: wxContext.OPENID,
    }).update({
      data: {
        isSubmitFour:true
        },
    })
  }else if(event.level==5){
    return await db.collection('scanCode')
    .where({
      brandidFive:event.brandid,
      openidFive: wxContext.OPENID,
    }).update({
      data: {
        isSubmitFive:true
        },
    })
  }else{
    return -1
  }
}